package com.ruoyi.web.controller.fenxi;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RDataDetail;
import com.ruoyi.system.service.IRDataDetailService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 样本明细管理Controller
 * 
 * @author ruoyi
 * @date 2022-09-25
 */
@Controller
@RequestMapping("/system/detail")
public class RDataDetailController extends BaseController
{
    private String prefix = "system/detail";

    @Autowired
    private IRDataDetailService rDataDetailService;

//    @RequiresPermissions("system:detail:view")
    @GetMapping()
    public String detail(Long parentId, Long orgId,ModelMap mmap)
    {
        mmap.put("parentId",parentId);
        mmap.put("orgId",orgId);
        return prefix + "/detail";
    }

    /**
     * 查询样本明细管理列表
     */
//    @RequiresPermissions("system:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RDataDetail rDataDetail)
    {
        startPage();
        List<RDataDetail> list = rDataDetailService.selectRDataDetailList(rDataDetail);
        return getDataTable(list);
    }

    /**
     * 导出样本明细管理列表
     */
//    @RequiresPermissions("system:detail:export")
    @Log(title = "样本明细管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RDataDetail rDataDetail)
    {
        List<RDataDetail> list = rDataDetailService.selectRDataDetailList(rDataDetail);
        ExcelUtil<RDataDetail> util = new ExcelUtil<RDataDetail>(RDataDetail.class);
        return util.exportExcel(list, "样本明细管理数据");
    }

    /**
     * 新增样本明细管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存样本明细管理
     */
//    @RequiresPermissions("system:detail:add")
    @Log(title = "样本明细管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RDataDetail rDataDetail)
    {
        return toAjax(rDataDetailService.insertRDataDetail(rDataDetail));
    }

    /**
     * 修改样本明细管理
     */
//    @RequiresPermissions("system:detail:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RDataDetail rDataDetail = rDataDetailService.selectRDataDetailById(id);
        mmap.put("rDataDetail", rDataDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存样本明细管理
     */
//    @RequiresPermissions("system:detail:edit")
    @Log(title = "样本明细管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RDataDetail rDataDetail)
    {
        return toAjax(rDataDetailService.updateRDataDetail(rDataDetail));
    }

    /**
     * 删除样本明细管理
     */
//    @RequiresPermissions("system:detail:remove")
    @Log(title = "样本明细管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rDataDetailService.deleteRDataDetailByIds(ids));
    }
}
